package com.egao.common.manage.college;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.student.constants.StudentConstants;
import com.egao.common.module.student.entity.Student;
import com.egao.common.module.student.entity.vo.StudentSignStatistics;
import com.egao.common.module.student.entity.vo.StudentSignStatisticsCollegeVO;
import com.egao.common.module.student.service.StudentService;
import com.egao.common.module.student.service.StudentSignService;
import com.egao.common.module.system.constants.DictConstants;
import com.egao.common.module.system.entity.College;
import com.egao.common.module.system.entity.Dict;
import com.egao.common.module.system.service.CollegeService;
import com.egao.common.module.system.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 学院数据统计管理
 * @author root
 */
@Api(tags = "学院数据统计管理")
@RestController
@RequestMapping("${api}")
public class CollegeStatisticsController extends BaseController {

    @Autowired
    private CollegeService collegeService;
    @Autowired
    private DictService dictService;
    @Autowired
    private StudentSignService studentSignService;
    @Autowired
    private StudentService studentService;

    @PreAuthorize("hasAuthority('college:statistics:sign')")
    @OperLog(value = "签约统计", desc = "签约统计")
    @ApiOperation("签约统计")
    @GetMapping("/college/statistics/sign")
    public JsonResult listCollege(StudentSignStatistics studentSignStatistics){
        String collegeCode = getLoginUser().getCollegeCode();
        if (StrUtil.isBlank(collegeCode)) {
            return JsonResult.error("未找到学院信息");
        }
        College college = collegeService.getByCode(collegeCode);
        if (null == college) {
            return JsonResult.error("未找到学院信息");
        }

        List<Dict> signCategoryList = dictService.cacheList(DictConstants.TYPE_SIGN_CATEGORY);
        studentSignStatistics.setCollegeCode(collegeCode);
        JsonResult jsonResult = studentSignService.signStatistics(studentSignStatistics);
        jsonResult.put("signCategoryList", signCategoryList);
        jsonResult.put("collegeName", college.getName());
        return jsonResult;
    }

    @PreAuthorize("hasAuthority('college:statistics:sign')")
    @OperLog(value = "学院就业率统计", desc = "学院就业率统计")
    @ApiOperation("学院就业率统计")
    @GetMapping("/college/statistics/sign-college")
    public JsonResult signCollege(Integer year, String xl, String tks) {
        String collegeCode = getLoginUser().getCollegeCode();
        if (StrUtil.isBlank(collegeCode)) {
            return JsonResult.error("未获取到学院信息");
        }

        List<StudentSignStatisticsCollegeVO> studentList = studentService.collegeStudentCount(year, xl, tks);
        if (studentList.size() == 0) {
            return JsonResult.error("暂无数据");
        }

        List<StudentSignStatisticsCollegeVO> studentSignList = studentSignService.collegeStudentSignCount(year, xl, tks, null, null);
        if (studentSignList.size() == 0) {
            return JsonResult.error("暂无数据");
        }

        // 结果集装载学院名称、学院人数
        // 结果集加入统计为0的学院
        for (StudentSignStatisticsCollegeVO student : studentList) {
            boolean b = false;
            for (StudentSignStatisticsCollegeVO sign : studentSignList) {
                if (student.getCollegeCode().equals(sign.getCollegeCode())) {
                    sign.setCollegeName(student.getCollegeName());
                    sign.setCollegeRate5(student.getCollegeRate5());
                    sign.setCollegeRate8(student.getCollegeRate8());
                    sign.setStudentCount(student.getStudentCount());
                    b = true;
                }
            }
            if (!b) {
                studentSignList.add(new StudentSignStatisticsCollegeVO(student.getCollegeName(), student.getCollegeCode(), student.getStudentCount()));
            }
        }

        // 定向生算进签约率
        List<Student> dxList = studentService.list(new QueryWrapper<Student>()
                .select("COUNT(1) id, college_code")
                .eq("year_id", year)
                .eq("pyfs", StudentConstants.PYFS_DX)
                .and("1".equals(xl), d -> d.eq("xl", "31").or().eq("xl", "25"))
                .eq("2".equals(xl), "xl", "11")
                .eq("3".equals(xl), "xl", "01")
                .and("4".equals(xl), d -> d.eq("xl", "11").or().eq("xl", "01"))
                .eq(!StrUtil.isBlank(tks), "tks", tks)
                .groupBy("college_code")
        );
        for (StudentSignStatisticsCollegeVO sign : studentSignList) {
            for (Student student : dxList) {
                if (sign.getCollegeCode().equals(student.getCollegeCode())) {
                    sign.setStudentSignCount(sign.getStudentSignCount() + student.getId());
                    sign.setXyjyCount(sign.getXyjyCount() + student.getId());
                }
            }
        }

        // 合计参数
        String totalName = "合计";
        Integer totalStudent = 0;
        Integer totalStudentSign = 0;
        Integer totalXyjy = 0;
        Integer totalZzcy = 0;
        Integer totalLhjy = 0;
        Integer totalZyzy = 0;
        Integer totalSx = 0;
        Integer totalCgcj = 0;
        Integer totalDjy = 0;

        // 开始计算百分比
        String rate = "#.##%";
        for (StudentSignStatisticsCollegeVO item : studentSignList) {
            Integer studentCount = item.getStudentCount();
            Integer studentSignCount = item.getStudentSignCount();

            BigDecimal studentRateB = NumberUtil.div(studentSignCount, studentCount);
            String studentRate = NumberUtil.decimalFormat(rate, studentRateB);
            item.setStudentRate(studentRate);

            BigDecimal xyjyRateB = NumberUtil.div(item.getXyjyCount(), studentCount);
            String xyjyRate = NumberUtil.decimalFormat(rate, xyjyRateB);
            item.setXyjyRate(xyjyRate);

            BigDecimal zzcyRateB = NumberUtil.div(item.getZzcyCount(), studentCount);
            String zzcyRate = NumberUtil.decimalFormat(rate, zzcyRateB);
            item.setZzcyRate(zzcyRate);

            BigDecimal lhjyRateB = NumberUtil.div(item.getLhjyCount(), studentCount);
            String lhjyRate = NumberUtil.decimalFormat(rate, lhjyRateB);
            item.setLhjyRate(lhjyRate);

            BigDecimal zyzyRateB = NumberUtil.div(item.getZyzyCount(), studentCount);
            String zyzyRate = NumberUtil.decimalFormat(rate, zyzyRateB);
            item.setZyzyRate(zyzyRate);

            BigDecimal sxRateB = NumberUtil.div(item.getSxCount(), studentCount);
            String sxRate = NumberUtil.decimalFormat(rate, sxRateB);
            item.setSxRate(sxRate);

            BigDecimal cgcjRateB = NumberUtil.div(item.getCgcjCount(), studentCount);
            String cgcjRate = NumberUtil.decimalFormat(rate, cgcjRateB);
            item.setCgcjRate(cgcjRate);

            Integer djyCount = studentCount - studentSignCount;
            BigDecimal djyRateB = NumberUtil.div(djyCount, studentCount);
            String djyRate = NumberUtil.decimalFormat(rate, djyRateB);
            item.setDjyRate(djyRate);
            item.setDjyCount(djyCount);

            totalStudent += studentCount;
            totalStudentSign += studentSignCount;
            totalXyjy += item.getXyjyCount();
            totalZzcy += item.getZzcyCount();
            totalLhjy += item.getLhjyCount();
            totalZyzy += item.getZyzyCount();
            totalSx += item.getSxCount();
            totalCgcj += item.getCgcjCount();
            totalDjy += item.getDjyCount();
        }

        // 合计
        StudentSignStatisticsCollegeVO total = new StudentSignStatisticsCollegeVO();
        total.setCollegeCode("0");
        total.setCollegeName(totalName);
        total.setStudentCount(totalStudent);
        total.setStudentSignCount(totalStudentSign);

        BigDecimal studentRateB = NumberUtil.div(totalStudentSign, totalStudent);
        String studentRate = NumberUtil.decimalFormat(rate, studentRateB);
        total.setStudentRate(studentRate);

        BigDecimal xyjyRateB = NumberUtil.div(totalXyjy, totalStudent);
        String xyjyRate = NumberUtil.decimalFormat(rate, xyjyRateB);
        total.setXyjyRate(xyjyRate);
        total.setXyjyCount(totalXyjy);

        BigDecimal zzcyRateB = NumberUtil.div(totalZzcy, totalStudent);
        String zzcyRate = NumberUtil.decimalFormat(rate, zzcyRateB);
        total.setZzcyRate(zzcyRate);
        total.setZzcyCount(totalZzcy);

        BigDecimal lhjyRateB = NumberUtil.div(totalLhjy, totalStudent);
        String lhjyRate = NumberUtil.decimalFormat(rate, lhjyRateB);
        total.setLhjyRate(lhjyRate);
        total.setLhjyCount(totalLhjy);

        BigDecimal zyzyRateB = NumberUtil.div(totalZyzy, totalStudent);
        String zyzyRate = NumberUtil.decimalFormat(rate, zyzyRateB);
        total.setZyzyRate(zyzyRate);
        total.setZyzyCount(totalZyzy);

        BigDecimal sxRateB = NumberUtil.div(totalSx, totalStudent);
        String sxRate = NumberUtil.decimalFormat(rate, sxRateB);
        total.setSxRate(sxRate);
        total.setSxCount(totalSx);

        BigDecimal cgcjRateB = NumberUtil.div(totalCgcj, totalStudent);
        String cgcjRate = NumberUtil.decimalFormat(rate, cgcjRateB);
        total.setCgcjRate(cgcjRate);
        total.setCgcjCount(totalCgcj);

        BigDecimal djyRateB = NumberUtil.div(totalDjy, totalStudent);
        String djyRate = NumberUtil.decimalFormat(rate, djyRateB);
        total.setDjyRate(djyRate);
        total.setDjyCount(totalDjy);

        studentSignList.add(0, total);

        // 只取本学院
        List<StudentSignStatisticsCollegeVO> list = studentSignList.stream()
                .filter(d -> collegeCode.equals(d.getCollegeCode())).collect(Collectors.toList());

        return JsonResult.ok().setData(list);
    }

    @PreAuthorize("hasAuthority('college:statistics:sign')")
    @OperLog(value = "所有学院就业率统计", desc = "所有学院就业率统计")
    @ApiOperation("所有学院就业率统计")
    @GetMapping("/college/statistics/all-sign-college")
    public JsonResult allSignCollege(Integer year, String xl, String tks) {
        String collegeCode = getLoginUser().getCollegeCode();
        if (StrUtil.isBlank(collegeCode)) {
            return JsonResult.error("未获取到学院信息");
        }

        List<StudentSignStatisticsCollegeVO> studentList = studentService.collegeStudentCount(year, xl, tks);
        if (studentList.size() == 0) {
            return JsonResult.error("暂无数据");
        }

        List<StudentSignStatisticsCollegeVO> studentSignList = studentSignService.collegeStudentSignCount(year, xl, tks, null, null);
        if (studentSignList.size() == 0) {
            return JsonResult.error("暂无数据");
        }

        // 结果集装载学院名称、学院人数
        // 结果集加入统计为0的学院
        for (StudentSignStatisticsCollegeVO student : studentList) {
            boolean b = false;
            for (StudentSignStatisticsCollegeVO sign : studentSignList) {
                if (student.getCollegeCode().equals(sign.getCollegeCode())) {
                    sign.setCollegeName(student.getCollegeName());
                    sign.setCollegeRate5(student.getCollegeRate5());
                    sign.setCollegeRate8(student.getCollegeRate8());
                    sign.setStudentCount(student.getStudentCount());
                    b = true;
                }
            }
            if (!b) {
                studentSignList.add(new StudentSignStatisticsCollegeVO(student.getCollegeName(), student.getCollegeCode(), student.getStudentCount()));
            }
        }

        // 定向生算进签约率
        List<Student> dxList = studentService.list(new QueryWrapper<Student>()
                .select("COUNT(1) id, college_code")
                .eq("year_id", year)
                .eq("pyfs", StudentConstants.PYFS_DX)
                .and("1".equals(xl), d -> d.eq("xl", "31").or().eq("xl", "25"))
                .eq("2".equals(xl), "xl", "11")
                .eq("3".equals(xl), "xl", "01")
                .and("4".equals(xl), d -> d.eq("xl", "11").or().eq("xl", "01"))
                .eq(!StrUtil.isBlank(tks), "tks", tks)
                .groupBy("college_code")
        );
        for (StudentSignStatisticsCollegeVO sign : studentSignList) {
            for (Student student : dxList) {
                if (sign.getCollegeCode().equals(student.getCollegeCode())) {
                    sign.setStudentSignCount(sign.getStudentSignCount() + student.getId());
                    sign.setXyjyCount(sign.getXyjyCount() + student.getId());
                }
            }
        }

        // 合计参数
        String totalName = "合计";
        Integer totalStudent = 0;
        Integer totalStudentSign = 0;
        Integer totalXyjy = 0;
        Integer totalZzcy = 0;
        Integer totalLhjy = 0;
        Integer totalZyzy = 0;
        Integer totalSx = 0;
        Integer totalCgcj = 0;
        Integer totalDjy = 0;

        // 开始计算百分比
        String rate = "#.##%";
        for (StudentSignStatisticsCollegeVO item : studentSignList) {
            Integer studentCount = item.getStudentCount();
            Integer studentSignCount = item.getStudentSignCount();

            BigDecimal studentRateB = NumberUtil.div(studentSignCount, studentCount);
            String studentRate = NumberUtil.decimalFormat(rate, studentRateB);
            item.setStudentRate(studentRate);

            BigDecimal xyjyRateB = NumberUtil.div(item.getXyjyCount(), studentCount);
            String xyjyRate = NumberUtil.decimalFormat(rate, xyjyRateB);
            item.setXyjyRate(xyjyRate);

            BigDecimal zzcyRateB = NumberUtil.div(item.getZzcyCount(), studentCount);
            String zzcyRate = NumberUtil.decimalFormat(rate, zzcyRateB);
            item.setZzcyRate(zzcyRate);

            BigDecimal lhjyRateB = NumberUtil.div(item.getLhjyCount(), studentCount);
            String lhjyRate = NumberUtil.decimalFormat(rate, lhjyRateB);
            item.setLhjyRate(lhjyRate);

            BigDecimal zyzyRateB = NumberUtil.div(item.getZyzyCount(), studentCount);
            String zyzyRate = NumberUtil.decimalFormat(rate, zyzyRateB);
            item.setZyzyRate(zyzyRate);

            BigDecimal sxRateB = NumberUtil.div(item.getSxCount(), studentCount);
            String sxRate = NumberUtil.decimalFormat(rate, sxRateB);
            item.setSxRate(sxRate);

            BigDecimal cgcjRateB = NumberUtil.div(item.getCgcjCount(), studentCount);
            String cgcjRate = NumberUtil.decimalFormat(rate, cgcjRateB);
            item.setCgcjRate(cgcjRate);

            Integer djyCount = studentCount - studentSignCount;
            BigDecimal djyRateB = NumberUtil.div(djyCount, studentCount);
            String djyRate = NumberUtil.decimalFormat(rate, djyRateB);
            item.setDjyRate(djyRate);
            item.setDjyCount(djyCount);

            totalStudent += studentCount;
            totalStudentSign += studentSignCount;
            totalXyjy += item.getXyjyCount();
            totalZzcy += item.getZzcyCount();
            totalLhjy += item.getLhjyCount();
            totalZyzy += item.getZyzyCount();
            totalSx += item.getSxCount();
            totalCgcj += item.getCgcjCount();
            totalDjy += item.getDjyCount();
        }

        // 合计
        StudentSignStatisticsCollegeVO total = new StudentSignStatisticsCollegeVO();
        total.setCollegeCode("0");
        total.setCollegeName(totalName);
        total.setStudentCount(totalStudent);
        total.setStudentSignCount(totalStudentSign);

        BigDecimal studentRateB = NumberUtil.div(totalStudentSign, totalStudent);
        String studentRate = NumberUtil.decimalFormat(rate, studentRateB);
        total.setStudentRate(studentRate);

        BigDecimal xyjyRateB = NumberUtil.div(totalXyjy, totalStudent);
        String xyjyRate = NumberUtil.decimalFormat(rate, xyjyRateB);
        total.setXyjyRate(xyjyRate);
        total.setXyjyCount(totalXyjy);

        BigDecimal zzcyRateB = NumberUtil.div(totalZzcy, totalStudent);
        String zzcyRate = NumberUtil.decimalFormat(rate, zzcyRateB);
        total.setZzcyRate(zzcyRate);
        total.setZzcyCount(totalZzcy);

        BigDecimal lhjyRateB = NumberUtil.div(totalLhjy, totalStudent);
        String lhjyRate = NumberUtil.decimalFormat(rate, lhjyRateB);
        total.setLhjyRate(lhjyRate);
        total.setLhjyCount(totalLhjy);

        BigDecimal zyzyRateB = NumberUtil.div(totalZyzy, totalStudent);
        String zyzyRate = NumberUtil.decimalFormat(rate, zyzyRateB);
        total.setZyzyRate(zyzyRate);
        total.setZyzyCount(totalZyzy);

        BigDecimal sxRateB = NumberUtil.div(totalSx, totalStudent);
        String sxRate = NumberUtil.decimalFormat(rate, sxRateB);
        total.setSxRate(sxRate);
        total.setSxCount(totalSx);

        BigDecimal cgcjRateB = NumberUtil.div(totalCgcj, totalStudent);
        String cgcjRate = NumberUtil.decimalFormat(rate, cgcjRateB);
        total.setCgcjRate(cgcjRate);
        total.setCgcjCount(totalCgcj);

        BigDecimal djyRateB = NumberUtil.div(totalDjy, totalStudent);
        String djyRate = NumberUtil.decimalFormat(rate, djyRateB);
        total.setDjyRate(djyRate);
        total.setDjyCount(totalDjy);

        studentSignList.add(0, total);

        // 只取本学院
        List<StudentSignStatisticsCollegeVO> list = studentSignList.stream()
                .filter(d -> collegeCode.equals(d.getCollegeCode())).collect(Collectors.toList());

        return JsonResult.ok().setData(list);
    }

    @PreAuthorize("hasAuthority('college:statistics:sign')")
    @OperLog(value = "专业就业率统计", desc = "专业就业率统计")
    @ApiOperation("专业就业率统计")
    @GetMapping("/college/statistics/sign-major")
    public JsonResult signMajor(Integer year, String xl) {
        String collegeCode = getLoginUser().getCollegeCode();
        if (StrUtil.isBlank(collegeCode)) {
            return JsonResult.error("未获取到学院信息");
        }

        List<StudentSignStatisticsCollegeVO> studentList = studentService.majorStudentCount(year, xl);
        if (studentList.size() == 0) {
            return JsonResult.error("暂无数据");
        }
        studentList = studentList.stream().filter(d -> collegeCode.equals(d.getCollegeCode())).collect(Collectors.toList());

        List<StudentSignStatisticsCollegeVO> studentSignList = studentSignService.majorStudentSignCount(year, xl);
        if (studentSignList.size() == 0) {
            return JsonResult.error("暂无数据");
        }
        studentSignList = studentSignList.stream().filter(d -> collegeCode.equals(d.getCollegeCode())).collect(Collectors.toList());

        // 结果集装载专业名称、专业人数
        // 结果集加入统计为0的专业
        for (StudentSignStatisticsCollegeVO student : studentList) {
            if (StrUtil.isBlank(student.getMajorCode())) {
                continue;
            }
            // 只取本学院
            if (!collegeCode.equals(student.getCollegeCode())) {
                continue;
            }
            boolean b = false;
            for (StudentSignStatisticsCollegeVO sign : studentSignList) {
                if (StrUtil.isBlank(sign.getMajorCode())) {
                    continue;
                }
                // 只取本学院
                if (!collegeCode.equals(sign.getCollegeCode())) {
                    continue;
                }
                if (student.getCollegeCode().equals(sign.getCollegeCode()) && student.getMajorCode().equals(sign.getMajorCode())) {
                    sign.setCollegeName(student.getCollegeName());
                    sign.setMajorName(student.getMajorName());
                    sign.setStudentCount(student.getStudentCount());
                    b = true;
                }
            }
            if (!b) {
                studentSignList.add(new StudentSignStatisticsCollegeVO(
                        student.getCollegeName(),
                        student.getCollegeCode(),
                        student.getMajorCode(),
                        student.getMajorName(),
                        student.getStudentCount(),
                        student.getCollegeSort()));
            }
        }

        // 定向生算进签约率
        List<Student> dxList = studentService.list(new QueryWrapper<Student>()
                .select("COUNT(1) id, college_code, major_code")
                .eq("year_id", year)
                .eq("pyfs", StudentConstants.PYFS_DX)
                .eq("college_code", collegeCode)
                .groupBy("college_code")
                .groupBy("major_code")
        );
        for (StudentSignStatisticsCollegeVO sign : studentSignList) {
            for (Student student : dxList) {
                if (sign.getCollegeCode().equals(student.getCollegeCode()) && sign.getMajorCode().equals(student.getMajorCode())) {
                    sign.setStudentSignCount(sign.getStudentSignCount() + student.getId());
                    sign.setXyjyCount(sign.getXyjyCount() + student.getId());
                }
            }
        }

        // 合计参数
        String totalName = "合计";
        Integer totalStudent = 0;
        Integer totalStudentSign = 0;
        Integer totalXyjy = 0;
        Integer totalZzcy = 0;
        Integer totalLhjy = 0;
        Integer totalZyzy = 0;
        Integer totalSx = 0;
        Integer totalCgcj = 0;
        Integer totalDjy = 0;

        // 开始计算百分比
        String rate = "#.##%";
        for (StudentSignStatisticsCollegeVO item : studentSignList) {
            Integer studentCount = item.getStudentCount();
            Integer studentSignCount = item.getStudentSignCount();

            BigDecimal studentRateB = NumberUtil.div(studentSignCount, studentCount);
            String studentRate = NumberUtil.decimalFormat(rate, studentRateB);
            item.setStudentRate(studentRate);

            BigDecimal xyjyRateB = NumberUtil.div(item.getXyjyCount(), studentCount);
            String xyjyRate = NumberUtil.decimalFormat(rate, xyjyRateB);
            item.setXyjyRate(xyjyRate);

            BigDecimal zzcyRateB = NumberUtil.div(item.getZzcyCount(), studentCount);
            String zzcyRate = NumberUtil.decimalFormat(rate, zzcyRateB);
            item.setZzcyRate(zzcyRate);

            BigDecimal lhjyRateB = NumberUtil.div(item.getLhjyCount(), studentCount);
            String lhjyRate = NumberUtil.decimalFormat(rate, lhjyRateB);
            item.setLhjyRate(lhjyRate);

            BigDecimal zyzyRateB = NumberUtil.div(item.getZyzyCount(), studentCount);
            String zyzyRate = NumberUtil.decimalFormat(rate, zyzyRateB);
            item.setZyzyRate(zyzyRate);

            BigDecimal sxRateB = NumberUtil.div(item.getSxCount(), studentCount);
            String sxRate = NumberUtil.decimalFormat(rate, sxRateB);
            item.setSxRate(sxRate);

            BigDecimal cgcjRateB = NumberUtil.div(item.getCgcjCount(), studentCount);
            String cgcjRate = NumberUtil.decimalFormat(rate, cgcjRateB);
            item.setCgcjRate(cgcjRate);

            Integer djyCount = studentCount - studentSignCount;
            BigDecimal djyRateB = NumberUtil.div(djyCount, studentCount);
            String djyRate = NumberUtil.decimalFormat(rate, djyRateB);
            item.setDjyRate(djyRate);
            item.setDjyCount(djyCount);

            totalStudent += studentCount;
            totalStudentSign += studentSignCount;
            totalXyjy += item.getXyjyCount();
            totalZzcy += item.getZzcyCount();
            totalLhjy += item.getLhjyCount();
            totalZyzy += item.getZyzyCount();
            totalSx += item.getSxCount();
            totalCgcj += item.getCgcjCount();
            totalDjy += item.getDjyCount();
        }

        studentSignList = studentSignList.stream().sorted(Comparator.comparing(StudentSignStatisticsCollegeVO::getCollegeSort)).collect(Collectors.toList());

        // 合计
        StudentSignStatisticsCollegeVO total = new StudentSignStatisticsCollegeVO();
        total.setCollegeCode("0");
        total.setCollegeName(totalName);
        total.setMajorCode("0");
        total.setMajorName(totalName);
        total.setStudentCount(totalStudent);
        total.setStudentSignCount(totalStudentSign);

        BigDecimal studentRateB = NumberUtil.div(totalStudentSign, totalStudent);
        String studentRate = NumberUtil.decimalFormat(rate, studentRateB);
        total.setStudentRate(studentRate);

        BigDecimal xyjyRateB = NumberUtil.div(totalXyjy, totalStudent);
        String xyjyRate = NumberUtil.decimalFormat(rate, xyjyRateB);
        total.setXyjyRate(xyjyRate);
        total.setXyjyCount(totalXyjy);

        BigDecimal zzcyRateB = NumberUtil.div(totalZzcy, totalStudent);
        String zzcyRate = NumberUtil.decimalFormat(rate, zzcyRateB);
        total.setZzcyRate(zzcyRate);
        total.setZzcyCount(totalZzcy);

        BigDecimal lhjyRateB = NumberUtil.div(totalLhjy, totalStudent);
        String lhjyRate = NumberUtil.decimalFormat(rate, lhjyRateB);
        total.setLhjyRate(lhjyRate);
        total.setLhjyCount(totalLhjy);

        BigDecimal zyzyRateB = NumberUtil.div(totalZyzy, totalStudent);
        String zyzyRate = NumberUtil.decimalFormat(rate, zyzyRateB);
        total.setZyzyRate(zyzyRate);
        total.setZyzyCount(totalZyzy);

        BigDecimal sxRateB = NumberUtil.div(totalSx, totalStudent);
        String sxRate = NumberUtil.decimalFormat(rate, sxRateB);
        total.setSxRate(sxRate);
        total.setSxCount(totalSx);

        BigDecimal cgcjRateB = NumberUtil.div(totalCgcj, totalStudent);
        String cgcjRate = NumberUtil.decimalFormat(rate, cgcjRateB);
        total.setCgcjRate(cgcjRate);
        total.setCgcjCount(totalCgcj);

        BigDecimal djyRateB = NumberUtil.div(totalDjy, totalStudent);
        String djyRate = NumberUtil.decimalFormat(rate, djyRateB);
        total.setDjyRate(djyRate);
        total.setDjyCount(totalDjy);

        studentSignList.add(0, total);

        return JsonResult.ok().setData(studentSignList);
    }

}
